%
%   This little program prints out prime numbers.  From the
%   TeXbook.
%
\newif\ifprime\newif\ifunknown
\newcount\p \newcount\d \newcount\a
\def\primes{\out{2}\out{3}\p=5
   \loop\iftrue\printifprime\advance\p by2\repeat}
\def\printifprime{\testprimality
   \ifprime\out{\number\p}\fi}
\def\testprimality{{\d=3\global\primetrue
   \loop\trialdivision
   \ifunknown\advance\d by2\repeat}}
\def\trialdivision{\a=\p
   \divide\a by\d
   \ifnum\a>\d\unknowntrue\else\unknownfalse\fi
   \multiply\a by\d
   \ifnum\a=\p \global\primefalse\unknownfalse\fi}
\def\out#1{\message{[#1]}}
%
%   Now we invoke the program.  Note, this is an infinite loop, so
%   use *BREAK* to exit.
%
\primes
